"""
绘制轮廓的拟合椭圆
"""
import cv2

img = cv2.imread('../data/cloud.png')
cv2.imshow('img',img)

img_gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
t,binary = cv2.threshold(img_gray,127,255,cv2.THRESH_BINARY)

# 提取轮廓坐标
cnts,hie = cv2.findContours(binary,
                                  cv2.RETR_EXTERNAL,
                                  cv2.CHAIN_APPROX_NONE)

# 根据轮廓的坐标，生成拟合椭圆的参数
params = cv2.fitEllipse(cnts[0])
# print(params)

# 绘制椭圆
cv2.ellipse(img,params,(0,0,255),2)
cv2.imshow('img',img)

cv2.waitKey()
cv2.destroyAllWindows()